/*
* 类中私有化变量或方法在方法前加#
* 例：#resolve(){
* }
* 1、Promise的状态只能改变一次，
* 2、异步任务的处理
* 3、自定义的函数都应该放入到微任务队列中
* 4、Promise对象的数据是可以反复读的
* 5、Promise对象能链式调用
* */
const PromiseStatus = {
    PENDING:0,
    RESOLVED:1,
    REJECT:2
}
class MyPromise{
    
    constructor(executor) {
        this.status = PromiseStatus.PENDING;
        this.data = null;
        executor(this.#resolve.bind(this),this.#reject.bind(this));
    }
    
    #resolve(value){
        if(this.status !== PromiseStatus.PENDING) return;
        this.data = value;
        this.status = PromiseStatus.RESOLVED;
    }
    #reject(){

    }

    then(onFullField,onReject){
        return new MyPromise((onFullField,onReject)=>{
            onFullField();
        });
    }

    //onFullField是解决then方法后的赋值
    onFullField(){

    }
}
new MyPromise((resolve,reason)=>{
    resolve('哈哈哈哈');
}).then((data)=>{
    console.log(data);
});
new Promise((resolve,reject)=>{
        resolve('promise')
}).then((data)=>{
    console.log(data);
})
